# encoding=utf-8

from PyQt5.QtWidgets import *
from PyQt5.QtCore import QStringListModel
from ui.ui_selectsheet import Ui_selectSheetDlg


class selectSheetDlg(QDialog, Ui_selectSheetDlg):

	def __init__(self, parent, listSheet):
		super(selectSheetDlg, self).__init__(parent)
		self.setupUi(self)
		self.m_sheetList = listSheet
		self.m_selected = ""
		self.initSignals()
		self.initListView()

	def initSignals(self):
		self.confirmBtn.clicked.connect(self.confirmSheet)
		self.confirmBtn.clicked.connect(self.parent().cbSelectedSheet)

	def initListView(self):
		model = QStringListModel()
		model.setStringList(self.m_sheetList)
		self.selectSheetListView.setModel(model)

	def confirmSheet(self):
		sheetName = self.m_sheetList[self.selectSheetListView.currentIndex().row()]
		self.parent().m_selectedSheet = sheetName
		self.close()
